<template>
    <div class="warp">
      <!-- logo 搜索框 -->
      <div class="header">
        <div class="logo">
          <img class="logoimg" src="@/assets/images/images_index/logo.png" alt="" />
        </div>
        <div class="inp" @click="gotoSearch">
          <van-icon class="ico" name="search" size="15px" />
          <input class="go_input" type="text" placeholder="搜索商品,共18542件好物" />
        </div>
        <div class="but">
          <van-button color="red" plain size="mini" @click="toLogin">登录</van-button>
        </div>
      </div>
  
      <!-- 滚动标签栏和下拉列表 -->
      <van-tabs v-model:active="active" class="tabs" color="red" swipeable @change="onClickTab">
        <van-tab title="推荐"></van-tab>
        <van-tab title="居家生活"></van-tab>
        <van-tab title="服饰生活"></van-tab>
        <van-tab title="宠物生活"></van-tab>
        <van-tab title="服饰鞋包"></van-tab>
        <van-tab title="美食酒水"></van-tab>
        <van-tab title="个户清洁"></van-tab>
        <van-tab title="运动旅行"></van-tab>
        <van-tab title="数码家电"></van-tab>
        <van-tab title="严选全球"></van-tab>
      </van-tabs>
  
      <!-- 轮播图 -->
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="(item, index) in NavSwiper" :key="index">
          <img class="itemImg" :src="item.picUrl" alt="" />
        </van-swipe-item>
      </van-swipe>
  
      <floor v-for="(item, index) in floorData2" :key="index" :floorData1="floorData2[index]" :itemList="item.itemList" ></floor>
    </div>
  </template>
  <script lang="ts">
  import { defineComponent } from 'vue'
  import { useRoute } from 'vue-router'
  import { Button, Swipe, SwipeItem, Tab, Tabs } from 'vant'
  import floor from './floor.vue'
  import router from '@/router'
  export default defineComponent({
    name: 'navitem',
    components: {
      [Button.name]: Button,
      [Swipe.name]: Swipe,
      [SwipeItem.name]: SwipeItem,
      [Tab.name]: Tab,
      [Tabs.name]: Tabs
    }
  })
  </script>
  <script setup lang="ts">
  import { computed, onMounted, ref, toRaw, watch } from 'vue'
  import { NavData } from '@/api/home/home'
  import type { daohangData } from '@/api/home/home'
  const routeID = ref()
  const active = ref(1)
  const route = useRoute()
  const ZYData = ref<daohangData>()
  const floorData = ref()
  let floorData1 = ref()
  routeID.value = route.params.id
  onMounted(() => {
    NavDatas()
  })
  async function NavDatas() {
    const res = await NavData()
    //@ts-ignore
    ZYData.value = res.data
    floorData.value = ZYData.value?.categoryItemList
    const data = toRaw(ZYData.value)
     floorData1.value = toRaw(floorData.value)
    console.log(data)
    console.log(floorData1)

  }
  
  function onClickTab(title: any) {
    active.value = title
    if (title === 0) {
      router.push({ path: '/index' })
    } else {
      router.push({ path: `/index/${title}` })
    }
  }
  
  const gotoSearch = () => {
    router.push({ path: '/search' })
  }
  
  const NavSwiper = computed(() => {
    return ZYData.value?.currentCategory.bannerList
  })
  const floorData2 = computed(() => {
    return floorData1.value?.splice(0,7)
  })

  // 去到登录
  const toLogin = () => {
    router.push('/login')
  }
  </script>
  
  <style scoped>
  .warp {
    width: 100%;
    height: 100%;
  }
  /* logo 搜索框 */
  .header {
    width: 100%;
    height: 44px;
    background-color: white;
    display: flex;
    align-items: center;
    padding: 8px 15px;
    box-sizing: border-box;
  }
  .logo {
    width: 69px;
    height: 20px;
    margin-right: 10px;
  }
  .logoimg {
    width: 69px;
    height: 20px;
  }
  .inp {
    display: flex;
    flex: 1;
    width: 100%;
    height: 28px;
    background-color: #ededed;
    border-radius: 5px;
    align-items: center;
  }
  .ico {
    margin-left: 15px;
  }
  .go_input {
    width: 100%;
    height: 20px;
    background-color: #ededed;
    font-size: 14px;
    border: none;
  }
  .but {
    margin-left: 10px;
    margin-top: -6px;
  }
  
  /* 导航栏 */
  .Tabnav {
    width: 100%;
    height: 30px;
    background-color: aqua;
  }
  
  /* 轮播图 */
  .my-swipe .van-swipe-item {
    width: 100%;
    height: 150px;
    color: #fff;
  }
  .itemImg {
    width: 100%;
    height: 100%;
  }
  </style>
  